package cn.wanho.service.impl;

import cn.wanho.dao.CmsPlaceMapper;
import cn.wanho.dto.CmsPlace;
import cn.wanho.rvo.PlaceVO;
import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.service.CmsPlaceService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CmsPlaceServiceImpl implements CmsPlaceService {
    @Resource
    private CmsPlaceMapper cmsPlaceMapper;

    /**
     * 创建教学点
     * @param placeName
     * @return
     */
    @Override
    public ResultVO addPlace(String placeName) {
        int i = cmsPlaceMapper.insert(placeName);
        if (i>0) {
            return ResultVO.success(ResultEnum.ADD_PLACE_SUCCESS.getResCode(), ResultEnum.ADD_PLACE_SUCCESS.getResMsg());
        }else{
            return ResultVO.failure(ResultEnum.ADD_PLACE_FAILURE.getResCode(), ResultEnum.ADD_PLACE_FAILURE.getResMsg());

        }
    }

    /**
     * 移除教学点
     * @param placeId
     * @return
     */
    @Override
    public ResultVO deletePlace(Integer placeId){
        int i = cmsPlaceMapper.deletePlaceById(placeId);
        if (i>0) {
            return ResultVO.success(ResultEnum.DELETE_PLACE_SUCCESS.getResCode(), ResultEnum.DELETE_PLACE_SUCCESS.getResMsg());
        }else{
            return ResultVO.failure(ResultEnum.DELETE_PLACE_FAILURE.getResCode(), ResultEnum.DELETE_PLACE_FAILURE.getResMsg());

        }

    }

    /**
     * 获取教学点
     * @return
     */
    @Override
    public ResultVO getPlaceList() {
        List<PlaceVO> placeList = cmsPlaceMapper.getPlaceList();
        return ResultVO.success(ResultEnum.GET_PlACE_SUCCESS.getResCode(), ResultEnum.GET_PlACE_SUCCESS.getResMsg(),placeList);
    }
}
